package com.ffcs.cn.action.desktopcontrol.smoptionpanel;

import com.supermap.desktop.controls.ui.UICommonToolkit;
import com.supermap.desktop.controls.ui.controls.SmDialog;
import com.supermap.desktop.core.ui.controls.GridBagConstraintsHelper;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;

/**
 * 弹出提示信息的对话框的示例对话框
 *
  */
public class DialogSmOptionPane extends SmDialog {
	private JButton buttonShowConfirmDialog;
	private JButton buttonShowConfirmDialogWithCancel;
	private JButton buttonShowConfirmYesOrNo;
	private JButton buttonShowErrorMessageDialog;
	private final ActionListener actionListener = e -> {
		if (e.getSource().equals(buttonShowConfirmDialog)) {
			UICommonToolkit.showConfirmDialog("提示信息", "提示标题");
		} else if (e.getSource().equals(buttonShowConfirmDialogWithCancel)) {
			UICommonToolkit.showConfirmDialogWithCancel("是否完成？");
		} else if (e.getSource().equals(buttonShowConfirmYesOrNo)) {
			UICommonToolkit.showConfirmDialogYesNo("是否完成？");
		} else if (e.getSource().equals(buttonShowErrorMessageDialog)) {
			UICommonToolkit.showErrorMessageDialog("错误提示");
		}
	};

	public DialogSmOptionPane() {
		setTitle("提示信息对话框");
		setSize(new Dimension(300, 400));
		initComponents();
		initLayout();
		registerEvents();
	}

	private void initComponents() {
		buttonShowConfirmDialog = new JButton("展示默认提示框");
		buttonShowConfirmDialogWithCancel = new JButton("展示含有‘否’的提示框");
		buttonShowConfirmYesOrNo = new JButton("展示是和否的提示框");
		buttonShowErrorMessageDialog = new JButton("展示错误的提示框");
	}

	private void initLayout() {
		this.setLayout(new GridBagLayout());
		this.add(buttonShowConfirmDialog, new GridBagConstraintsHelper(0, 0, 1, 1)
				.setInsets(GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setWeight(0, 0)
				.setFill(GridBagConstraints.BOTH));
		this.add(buttonShowConfirmDialogWithCancel, new GridBagConstraintsHelper(0, 1, 1, 1)
				.setInsets(GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setWeight(0, 0)
				.setFill(GridBagConstraints.BOTH));
		this.add(buttonShowConfirmYesOrNo, new GridBagConstraintsHelper(0, 2, 1, 1)
				.setInsets(GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setWeight(0, 0)
				.setFill(GridBagConstraints.BOTH));
		this.add(buttonShowErrorMessageDialog, new GridBagConstraintsHelper(0, 3, 1, 1)
				.setInsets(GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.FRAME_CONTROL_GAP, GridBagConstraintsHelper.CONTROLS_GAP)
				.setWeight(0, 0)
				.setFill(GridBagConstraints.BOTH));
	}

	private void registerEvents() {
		buttonShowErrorMessageDialog.addActionListener(actionListener);
		buttonShowConfirmDialogWithCancel.addActionListener(actionListener);
		buttonShowConfirmDialog.addActionListener(actionListener);
		buttonShowConfirmYesOrNo.addActionListener(actionListener);
	}
}
